package tingche.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import tingche.bean.CarBean;
import util.JDBCUtils;

public class CarDao {
	Connection con=null;
	PreparedStatement ps=null;
	
	public int insert(CarBean car) {
		String sql="insert into c_car(chepai,height) values(?,?)";
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			ps.setString(1, car.getChepai());
			ps.setBigDecimal(2, car.getHeight());
			return ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	public CarBean selectByPai(CarBean car) {
		String sql="select * from c_car where chepai=?";
		ResultSet rs=null;
		try {
			con=JDBCUtils.getConnection();
			ps=con.prepareStatement(sql);
			ps.setString(1, car.getChepai());
			rs=ps.executeQuery();
			while(rs.next()) {
				CarBean car1=new CarBean();
				car1.setChepai(rs.getString("chepai"));
				car1.setHeight(rs.getBigDecimal("height"));
				return car1;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
